package com.panopset.rdb;

import java.io.StringWriter;
import java.sql.ResultSet;

/**
 *
 * @author Karl Dinwiddie
 *
 */
public abstract class Field {

    /**
     *
     * @param fieldName
     *            Field name, will be converted to upper case.
     */
    public Field(final String fieldName) {
        name = fieldName.toUpperCase();
    }

    /**
     * Field name.
     */
    private final String name;

    /**
     * @return field name.
     */
    public final String getName() {
        return name;
    }

    /**
     *
     * @return Data type.
     */
    public abstract String getDataType();

    /**
     * @return SQL field definition.
     */
    public final String getDefinition() {
        StringWriter sw = new StringWriter();
        sw.append(getName());
        sw.append(" ");
        sw.append(getDataType());
        return sw.toString();
    }
    /**
     * @param rs
     *            Result set.
     * @return Value.
     * @throws Exception exception.
     */
    public abstract Object getValueFromResultSet(final ResultSet rs)
            throws Exception;

    /**
     * @return Quote if a non numeric field.
     */
    public abstract String getQuoteIfNecessary();
}
